package com.qunar.flight.myserver;

import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class AcceptHandler2 implements Handler {
	private ServerSocketChannel channel;
	private Dispatcher dsp;
	private SelectionKey sk;

	AcceptHandler2(ServerSocketChannel ssc, Dispatcher dsp) {
		channel = ssc;
		this.dsp = dsp;
	}

	public void handle(SelectionKey sk) {
		try {
			System.out.println(getClass());
			SocketChannel sc = channel.accept();// get The socket channel for
												// the
												// new connection
			sc.configureBlocking(false);
			Handler rh = new RequestHandler2(sc);
			rh.setSk(sk);
			dsp.register(sc, SelectionKey.OP_READ, rh);// selector�ϰ�channel��channel���и���Ȥ���¼�,���и���Ȥ���¼�����ʱ���channel�Ϳ���ʹ����
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void run() {
		try {
			handle(sk);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void setSk(SelectionKey sk) {

	}
}
